from aiohttp import RequestInfo
from fastapi import Form, Request, APIRouter, Depends
from app.config import SessionLocal, engine
from app.sql import models
from . import crud, schema
from sqlalchemy.orm import Session


auth_router = APIRouter(prefix="/api/auth")

def get_db():
    db = SessionLocal()
    try:
        yield db
    finally:
        db.close()


@auth_router.post("/login")
def login(model: schema.UserAuth,db: Session = Depends(get_db)):
    return crud.is_creditnail_valid(db, model.login, model.password)


@auth_router.post("/register")
def register(model: schema.UserAuth,db: Session = Depends(get_db)):
    return crud.add_user(db, model.login, model.password)